-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(neon): JsFunction::bind()
and Object::prop()
#1056
Conversation
JsFunction::bind()
JsFunction::bind()
and Object::prop()
ca0fce8
to
589fabc
Compare
…unction using the Try{From,Into}Js traits.
…ing BindOptions::apply()
…ng non-functions with .bind()
…is already implemented for NeonResult
- tests for both strict and sloppy mode functions to show it works on primitives
…pe parameter other than for the key
…alling .bind(), since it's performed when calling .apply()
Co-authored-by: K.J. Valencik <kjvalencik@gmail.com>
…f a weird inconsistency between the callee being something other than a Handle vs the other args
…as the other impls
…cise typing - add PropOptions::this() to return the object - add PropOptions::prop() to enable assignment chaining
- BindOptions::exec() - rename BindOptions::apply() to BindOptions::call() - eliminate call_method_with() from API docs
83a0fbd
to
7f1d108
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code and API look great! A couple small suggestions for the doc examples, but it's ready to go!
@@ -1158,6 +1120,7 @@ impl JsFunction { | |||
/// Calls this function. | |||
/// | |||
/// **See also:** [`JsFunction::call_with`]. | |||
#[deprecated(since = "TBD", note = "use `JsFunction::bind` instead")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this one should be deprecated. It's the low level function that doesn't have the overhead of casting and deserialization. I think we should keep it.
Implements `JsFunction::bind()`, which creates a builder for calling a function using the `Try{From,Into}Js` traits. ```rust let n = f.bind(&mut cx) .args((1, 2, 3))? .arg(4)? .arg_with(|cx| Ok(cx.number(5)))? .call::<f64>()?; ``` Also implements `Object::prop()`, which creates a builder for accessing object properties using the `Try{From,Into}Js` traits. ```rust let x: f64 = obj .prop(&mut cx, "x") .get()?; obj.prop(&mut cx, "y") .set(x)?; let s: String = obj.prop(&mut cx, "toString") .bind()? .call()?; ``` Finally, it offers a shorthand convenience method `Object::method()`, which extracts an object property and binds it as a method: ```rust let s: String = obj.method(&mut cx, "toString").call()?; ``` --------- Co-authored-by: K.J. Valencik <kjvalencik@gmail.com>
This PR implements
JsFunction::bind()
, which creates a builder for calling a function using theTry{From,Into}Js
traits.It also implements
Object::prop()
, which creates a builder for accessing object properties using theTry{From,Into}Js
traits.Finally, it offers a shorthand convenience method
Object::method()
, which extracts an object property and binds it as a method: